#!/usr/bin/perl

# $Id: 00_installed_modules.t 7 2010-11-12 07:51:36Z dolbanavt@googlemail.com $
# $Date: 2010-11-12 09:51:51 +0200 (Птн, 12 Ноя 2010) $
# $HeadURL: https://tegusigalpa.googlecode.com/svn/branches/storage_init/t/00_installed_modules.t $
# $LastChangedRevision: 63 $

use utf8;
use strict;
use warnings;
use version 0.77; # even for Perl v.5.10.0
use FindBin qw( $RealBin );
use File::Spec::Functions qw( catfile );
use Test::More;
use English qw( -no_match_vars );

BEGIN {
    push @INC, catfile( $RealBin, '..', 'base_lib' );
}

# 0 means we dont care
my %requirement = (
    # Perl core modules
    'Test::Harness'     => 0,
    'Test::Builder'     => 0,
    'Carp'              => 0,
    'Pod::Usage'        => 0,
    'Getopt::Long'      => '2.24',
    'parent'            => 0,

    # CPAN
    'Const::Fast'               => 0,
    'IPC::Open3::Utils'         => 0,
    'lib::abs'                  => 0,
    'JSON::RPC::Server::Daemon' => 0,
    'JSON::RPC::Client'         => 0,
    'Object::Container'         => 0,
    'Test::Exception'           => 0,
    'Class::Accessor::Fast'     => 0,
    'DBD::Mock'                 => 0,

    # base_lib
    'JIP::ToolSet'      => '1.9.6',
    'JIP::Utils'        => '1.9.6',
    'JIP::BaseClass'    => '1.9.6',
    'Proc::Lock'        => '1.9.6',
    'Configurator'      => '1.9.6',
    'Log'               => '1.9.6',
    'Proc::Daemon'      => '1.9.6',
    'Log::Console'      => '1.9.6',
    'SQLWrapper'        => '1.9.6',
);

if ( %requirement ) {
    plan tests => ( scalar keys %requirement ) * 2;

    for my $each_module ( sort keys %requirement ) {
        my $wanted = $requirement{ $each_module };

        if ( use_ok $each_module ) {
            if ( $wanted ) {
                my $actual = $each_module->VERSION;

                if ( version->parse( $actual ) >= version->parse( $wanted ) ) {
                    pass $each_module .' has actual version '. $actual;
                }
                else {
                    fail $each_module .' has actual version ('. $actual. ')'
                        . ' aldest then wanted ('. $wanted .')';
                }
            }
            else {
                pass $each_module .' loaded';
            }
        }
        else {
            fail 'cannot load '. $each_module;
        }
    }
}
else {
    plan skip_all => 'without requirements';
}
